package dav.mobile.garuda.components;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;

public class SoundManager {
	//Musics
	public static Music m_MenuMusic;
	public static Music m_BaliBorneoMusic;
	public static Music m_BunakenTobaMusic;
	public static Music m_PrologEpilogMusic;
	public static Music m_SceneMusic;
	
	//Sounds
	public static Sound m_BungaSound;
	public static Sound m_BurungSound;
	public static Sound m_LandakSound;
	public static Sound m_MenuSound;
	public static Sound m_StupaSound;
	public static Sound m_LumpingSound;
	
	public static void Load() {
		//Load BGM
		m_MenuMusic = Gdx.audio.newMusic(Gdx.files.internal(Constants.GAME_SOUND_BGM_FOLDER + "menu.ogg"));
		m_BaliBorneoMusic = Gdx.audio.newMusic(Gdx.files.internal(Constants.GAME_SOUND_BGM_FOLDER + "bali-borneo.ogg"));
		m_BunakenTobaMusic = Gdx.audio.newMusic(Gdx.files.internal(Constants.GAME_SOUND_BGM_FOLDER + "bunaken-toba.ogg"));
		m_PrologEpilogMusic = Gdx.audio.newMusic(Gdx.files.internal(Constants.GAME_SOUND_BGM_FOLDER + "prolog-epilog.ogg"));
		m_SceneMusic = Gdx.audio.newMusic(Gdx.files.internal(Constants.GAME_SOUND_BGM_FOLDER + "scene.ogg"));
		
		//Load SFX
		m_BungaSound = Gdx.audio.newSound(Gdx.files.internal(Constants.GAME_SOUND_SFX_FOLDER + "bunga.ogg"));
		m_BurungSound = Gdx.audio.newSound(Gdx.files.internal(Constants.GAME_SOUND_SFX_FOLDER + "burung.ogg"));
		m_LandakSound = Gdx.audio.newSound(Gdx.files.internal(Constants.GAME_SOUND_SFX_FOLDER + "landak.ogg"));
		m_MenuSound = Gdx.audio.newSound(Gdx.files.internal(Constants.GAME_SOUND_SFX_FOLDER + "menu button.ogg"));
		m_StupaSound = Gdx.audio.newSound(Gdx.files.internal(Constants.GAME_SOUND_SFX_FOLDER + "stupa.ogg"));	
		m_LumpingSound = Gdx.audio.newSound(Gdx.files.internal(Constants.GAME_SOUND_SFX_FOLDER + "kuda.ogg"));	
	}
	
	public static void PlayBGM(Music music, boolean loop, float volume) {
        if(Constants.GAME_SOUND_ENABLED) {  
            music.setVolume(volume);
        } else music.setVolume(0);
        
        music.setLooping(loop);
        music.play();
    }
	
	public static void PauseBGM(Music music) {
		music.pause();
	}
	
	//Default playing music
	public static void PlayBGM(Music music) {
		PlayBGM(music, true, 1.0f);
	}
	
	public static void StopBGM(Music music) {
		if (music.isPlaying()) music.stop();
	}
	
	public static void PlaySFX(Sound sound) {
        if(Constants.GAME_SOUND_ENABLED) {
            sound.play();
        }
    }
	
	public static void Dispose() {
		m_MenuMusic.dispose();
		m_BaliBorneoMusic.dispose();
		m_BunakenTobaMusic.dispose();
		m_PrologEpilogMusic.dispose();
		m_SceneMusic.dispose();
		
		m_BungaSound.dispose(); 
		m_BurungSound.dispose();
		m_LandakSound.dispose();
		m_MenuSound.dispose();
		m_StupaSound.dispose();
		m_LumpingSound.dispose();
	}
}
